package graph.views.DrawingForm;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PropertyPanel extends JPanel {
	private JLabel vertexXYLabel;
	private JTextField vertexXYTextField;

	private JLabel edgeStartXYLabel;
	private JTextField edgeStartXYTextField;

	private JLabel edgeEndXYLabel;
	private JTextField edgeEndXYTextField;
	private JTextArea result;
	
	private JPanel panel;
	private GridBagLayout layout;
	private GridBagConstraints constraints;

	public PropertyPanel() {
		vertexXYLabel = new JLabel("(x, y): ");
		vertexXYTextField = new JTextField("(100, 200)", 16);
		edgeStartXYLabel = new JLabel("start(x1, y1): ");
		edgeStartXYTextField = new JTextField("(100, 200)", 16);
		edgeEndXYLabel = new JLabel("end(x2, y2): ");
		edgeEndXYTextField = new JTextField("(200, 200)", 16);
		result = new JTextArea(20, 10);
		
		panel = new JPanel();
		layout = new GridBagLayout();
		panel.setLayout(layout);
		constraints = new GridBagConstraints();
		this.add(panel, BorderLayout.EAST);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.anchor = GridBagConstraints.WEST;
		addComponent(vertexXYLabel, 0, 0, 1, 1);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		addComponent(vertexXYTextField, 0, 1, 1, 1);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.anchor = GridBagConstraints.WEST;
		addComponent(edgeStartXYLabel, 1, 0, 1, 1);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		addComponent(edgeStartXYTextField, 1, 1, 1, 1);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.anchor = GridBagConstraints.WEST;
		addComponent(edgeEndXYLabel, 2, 0, 1, 1);

		constraints.fill = GridBagConstraints.HORIZONTAL;
		addComponent(edgeEndXYTextField, 2, 1, 1, 1);
		
		constraints.fill = GridBagConstraints.HORIZONTAL;
		addComponent(result, 3, 0, 2, 2);

		this.setPreferredSize(new Dimension(250, 100));
		this.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
		this.setBackground(Color.BLUE);
	}

	private void addComponent(Component component, int row, int column,
			int width, int height) {
		addComponent(component, row, column, width, height, 0.0, 0.0);
	}

	private void addComponent(Component component, int row, int column,
			int width, int height, double weightx, double weighty) {

		constraints.gridx = column;
		constraints.gridy = row;
		constraints.gridwidth = width;
		constraints.gridheight = height;
		constraints.weightx = weightx;
		constraints.weighty = weighty;

		layout.setConstraints(component, constraints);
		panel.add(component);
	}
	
	public void setText(String text) {
		result.setText(text);
	}
}
